using System.Collections.Generic;
using UnityEngine;

namespace UnityEditor
{
    public class BaseEditorWindow : BaseWindow
    {
        #region 焦点控制

        /// <summary>
        /// 获得焦点时
        /// </summary>
        public override void OnFocus()
        {
            if (singleWindow)
            {
                base.OnFocus();
            }
        }

        public override void OnLostFocus()
        {
            if (singleWindow)
            {
                base.OnLostFocus();
            }
        }

        #endregion

        public bool singleWindow;
        public int tempHeight = 100;
        public void OnGUI()
        {
            if (EditorApplication.isCompiling)
            {
                Close();
                return;
            }
            if (singleWindow)
                DrawGUI();
        }

        public virtual void DrawGUI()
        {
            tempHeight = singleWindow ? 0 : 40;
        }

        public static T NewWindow<T>(bool utility, string title, bool singleWindow, int width = 300, int height = 450) where T : BaseEditorWindow
        {
            var instance = singleWindow ? GetWindow<T>(utility, title) : CreateInstance<T>();
            instance.singleWindow = singleWindow;
            //if (singleWindow)
            {
                instance.minSize = instance.maxSize = new Vector2(width, height);
            }
            return instance;
        }

        public static T NewWindow<T>(bool singleWindow) where T : BaseEditorWindow
        {
            var instance = singleWindow ? GetWindow<T>(typeof(T).Name) : CreateInstance<T>();
            instance.singleWindow = singleWindow;
            return instance;
        }


        #region 打开列表栏

        protected Dictionary<object, bool> foldOutDic = new Dictionary<object, bool>();

        protected bool isFoldOut(object key)
        {
            bool res = false;
            if (!foldOutDic.TryGetValue(key, out res))
            {
                foldOutDic.Add(key, false);
            }
            return res;
        }

        protected void SetFoldOut(object key, bool foldout)
        {
            foldOutDic[key] = foldout;
        }

        #endregion
    }
}
